package cn.maxhou.service.impl;

import cn.maxhou.entity.SysRole;
import cn.maxhou.mapper.SysRoleMapper;
import cn.maxhou.service.SysRoleService;
import cn.maxhou.util.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("sysRoleService")
public class SysRoleServiceImpl implements SysRoleService {
    private static final Logger LOGGER= LoggerFactory.getLogger(SysUserServiceImpl.class);

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> findAll() throws Exception {
        try{
            return sysRoleMapper.getAll();
        }catch (Exception e){
            LOGGER.error("执行SysUserServiceImpl.findAll()方法出现异常",e);
            throw e;
        }
    }

    @Override
    public boolean saveOrUpdate(SysRole entity) throws Exception {
        try{
            if(entity.getId()==null){
               return sysRoleMapper.insert(entity)>0;
            }else {
               return sysRoleMapper.update(entity)>0;
            }
        }catch (Exception e){
            LOGGER.error("执行SysUserServiceImpl.saveOrUpdate(SysRole)方法出现异常",e);
            throw e;
        }
    }

    @Override
    public SysRole findById(Long id) throws Exception {
        return sysRoleMapper.getById(id);
    }

    @Override
    public int deleteById(Long id) throws Exception {
        return sysRoleMapper.deleteById(id);
    }

    @Override
    public SysRole getByCode(String code) {
        return sysRoleMapper.getByCode(code);
    }
}
